package com.huangdada.hfweather.mapper;

import com.huangdada.hfweather.bean.City;
import com.huangdada.hfweather.bean.SJCity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 城市DAO
 * @PROJECT_NAME: hf-weather
 * @CLASS_NAME:
 * @Author: huanglibin
 * @Date: 2020-03-31 21:56
 * @Version: 1.0
 */
@Mapper
//@Component
public interface CityMapper {

    /**
     * 添加城市数据
     * @param city
     * @return
     */
    @Insert("insert into citys(city_id,city_en,city_cn,country_code,country_en,country_cn,province_en,province_cn,admin_district_en,admin_district_cn,latitude,longitude,ad_code) " +
            "values (#{cityId},#{cityEn} ,#{cityCn},#{countryCode} ,#{countryEn},#{countryCn} ,#{provinceEn} ,#{provinceCn},#{adminDistrictEn} ,#{adminDistrictCn} ,#{latitude} ,#{longitude} ,#{adCode}    )")
    public Integer addCityInfo(City city);

    /**
     * SOJSON城市数据
     * @param city
     * @return
     */
    @Insert("insert into sjcitys(id,pid,city_code,city_name,post_code,area_code,ctime)" +
            "values (#{id},#{pid} ,#{cityCode} ,#{cityName} ,#{postCode} ,#{areaCode} ,#{ctime} )")
    public Integer addSJCityInfo(SJCity city);

    @Select("select * from ltf_city")
    public List<SJCity> querySjCitys();

    /**
     * 查询城市信息
     * @return
     */
    @Select("select * from citys")
    @Results(id = "citysMap",value = {
            @Result(column ="city_id",property = "cityId",jdbcType = JdbcType.VARCHAR),
            @Result(column ="city_en",property = "cityEn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="city_cn",property = "cityCn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="country_code",property = "countryCode",jdbcType = JdbcType.VARCHAR),
            @Result(column ="country_en",property = "countryEn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="country_cn",property = "countryCn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="province_en",property = "provinceEn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="province_cn",property = "provinceCn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="admin_district_en",property = "adminDistrictEn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="admin_district_cn",property = "adminDistrictCn",jdbcType = JdbcType.VARCHAR),
            @Result(column ="latitude",property = "latitude",jdbcType = JdbcType.VARCHAR),
            @Result(column ="longitude",property = "longitude",jdbcType = JdbcType.VARCHAR),
            @Result(column ="ad_code",property = "adCode",jdbcType = JdbcType.VARCHAR)
    })
    List<City> queryCitys();

}
